package com.zzptc.myapplication5a1022;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.media.Image;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";
    ListView listView;
   List<Student> list;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        listView=findViewById(R.id.lv_mzb);//实例化控件
        list=new ArrayList<>();//集合类对象
        for (int i=0;i<50;i++){
            Student student= new Student(R.mipmap.ic_launcher,i,"姓名"+i,new Date()+ "");
            list.add(student);//创造数据并放到实体类里
        }
        for (Student s:list){
            Log.d(TAG, s.getName());
            Log.d(TAG, s.getTime());
        }
       MyAdapter  myAdapter=new  MyAdapter();
        listView.setAdapter(myAdapter);//与适配器关联起来
    }
    class MyAdapter extends BaseAdapter{
        @Override
        public int getCount() {
            return list.size();
        }

        @Override
        public Object getItem(int i) {
            return null;
        }

        @Override
        public long getItemId(int i) {
            return 0;
        }

        @SuppressLint("ResourceType")
        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            //要数据
            Student student =list.get(i);
            //要做界面了
            View view1 =View.inflate(MainActivity.this,R.layout.item_stm,null);
            //要绑定数据了
           ImageView a1=view1.findViewById(R.id.a1);
             a1.setImageResource(R.mipmap.w2);
            TextView a2=view1.findViewById(R.id.a2);
            a2.setText(student.getId()+"");//要将整数转成字符窜
            TextView a3=view1.findViewById(R.id.a3);
            a3.setText(student.getName());
            TextView a4=view1.findViewById(R.id.a4);
             a4 .setText(student.getTime());
            return view1;
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.myoption,menu);
      //  menu.add(0,1,1,"关于");
        //menu.add(0,1,1,"账号");
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
       // Toast.makeText(this,""+item.getItemId(),Toast.LENGTH_SHORT).show();
        return true;
    }
}
